/*
 * log.h
 *
 *  Created on: 2021年6月10日
 *      Author: yedapeng
 */

#ifndef LOG_H_
#define LOG_H_

#include "SEGGER_RTT.h"
#include "SEGGER_SYSVIEW.h"

#define LOG_DEBUG 1

#define LOG_PROTO(type,color,format,...)            \
        SEGGER_RTT_printf(0,"%s[%02d:%02d:%02d.%03d]%s"format"%s", \
                          color,                    \
                          SEGGER_SYSVIEW_X_GetTimestamp()/(1000*60*60), \
                          SEGGER_SYSVIEW_X_GetTimestamp()/(1000*60)%60, \
                          SEGGER_SYSVIEW_X_GetTimestamp()/(1000)%60, \
                          SEGGER_SYSVIEW_X_GetTimestamp()%1000, \
                          type,                     \
                          ##__VA_ARGS__,            \
                          RTT_CTRL_RESET)

#if LOG_DEBUG




#define LOG_CLEAR() SEGGER_RTT_WriteString(0, "  "RTT_CTRL_CLEAR)
#define LOG(format,...) LOG_PROTO("","",format,##__VA_ARGS__)
#define LOGI(format,...) LOG_PROTO("   Info:", RTT_CTRL_TEXT_BRIGHT_GREEN , format, ##__VA_ARGS__)
#define LOGW(format,...) LOG_PROTO("Warning:", RTT_CTRL_TEXT_BRIGHT_YELLOW, format, ##__VA_ARGS__)
#define LOGE(format,...) LOG_PROTO("  Error:", RTT_CTRL_TEXT_BRIGHT_RED   , format, ##__VA_ARGS__)
#define LOGT(format,...) LOG_PROTO("  TEST:", RTT_CTRL_TEXT_BRIGHT_GREEN   , format, ##__VA_ARGS__)

#else
#define LOG_CLEAR(...)
#define LOG(...)
#define LOGI(...)
#define LOGW(...)
#define LOGE(...)

#endif
//#define LOGE(format,...) LOG_PROTO("  Error:", RTT_CTRL_TEXT_BRIGHT_RED   , format, ##__VA_ARGS__)
//#define LOGT(format,...) LOG_PROTO("  TEST:", RTT_CTRL_TEXT_BRIGHT_GREEN   , format, ##__VA_ARGS__)

#endif /* LOG_H_ */
